//
//  LoginViewController.m
//  UIProject-A
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 何 旭. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginView.h"
#import "RegistView.h"
#import "LTView.h"
#import "RegistViewController.h"

@interface LoginViewController ()<UITextFieldDelegate>

@end

@implementation LoginViewController
-(void)loadView{
    self.view = [[LoginView alloc]initWithFrame:[UIScreen mainScreen].bounds];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    LoginView *loginView = (LoginView *)self.view;
    loginView.usernameView.TextField.delegate = self;
    loginView.passwordView.TextField.delegate = self;
    
    self.title = @"登  陆";
    
    //登陆按钮
    [loginView.loginButton addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
    //注册按钮
    [loginView.registButton addTarget:self action:@selector(regist:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    imageView.image = [UIImage imageNamed:@"1.png"];
    [self.view addSubview:imageView];
    [self.view sendSubviewToBack:imageView];

}

-(void)login:(UIButton *)button{
    LoginView *loginView = (LoginView *)self.view;
    if (loginView.usernameView.TextField.text.length > 0 && loginView.passwordView.TextField.text.length > 0) {
        if ([loginView.usernameView.TextField.text isEqualToString:@"hexu"] && [loginView.passwordView.TextField.text isEqualToString:@"123456"]) {
            UIAlertView *successAlerView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登录成功" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [successAlerView show];
        }else{
            UIAlertView *errorAlerView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"信息输入不正确，请重新输入" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [errorAlerView show];
        }
        
    }else{
        UIAlertView *errorAlerView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"信息不能为空，请重新输入" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [errorAlerView show];
    }
}


-(void)regist:(UIButton *)button{

    RegistViewController *registVC = [[RegistViewController alloc] init];
    
    [self.navigationController pushViewController:registVC animated:YES];
    
}
//键盘回收代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    LoginView *loginView = (LoginView *)self.view;
    if (textField == loginView.usernameView.TextField) {
        [loginView.passwordView.TextField becomeFirstResponder];
    }else{
        [loginView.passwordView.TextField resignFirstResponder];
    }
    return self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
